
//
// 130316 - AH - Created.
//

package org.japril.servlet;

/**
 * <p>
 *   Base class for objects that represents elements of a HTTP protocol.
 * </p>
 * @author Arne Halvorsen (AH)
 */
public abstract class HttpProtocolElement 
{
  private String m_name;
  
  private String m_desc=null;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param name {@link #getName()}.
   */
  protected HttpProtocolElement(String name)
  {
    if (name==null)
    {
      throw new NullPointerException("name");
    }
    
    name=name.trim();
    if (name.length()==0)
    {
      throw new IllegalArgumentException("name is the empty string");
    }
    
    m_name=name;
  }
  
  /**
   * <p>
   *   Gets name.
   * </p>
   * @return Name.
   */
  public final String name(){ return m_name; }
  
  /**
   * <p>
   *   Sets name.
   * </p>
   * @param name Name.
   * @throws IllegalArgumentException If {@code name} is the empty string.
   */
  public final void name(String name)
  {
    if (name==null)
    {
      throw new NullPointerException("name");
    }
    
    name=name.trim();
    if (name.length()==0)
    {
      throw new IllegalArgumentException("name is the empty string");
    }
    
    m_name=name;
  }
  
  /**
   * <p>
   *   Sets description.
   * </p>
   * @param desc Description, {@code null}, the empty or blank string clears.
   * @return {@code this}.
   */
  public final HttpProtocolElement description(String desc)
  {
    desc=(desc==null) ? "" : desc.trim();
    m_desc=(desc.length()==0) ? null : desc;
    return this;
  }
  
  /**
   * <p>
   *   Gets description.
   * </p>
   * @return Description or {@code null} if not sat.
   */
  public final String description(){ return m_desc; }
  
}
